package cn.zktr.Personnel.model.service.zhouxiong;

import java.sql.Timestamp;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.zktr.Personnel.model.pojos.PerCwaRem;
import cn.zktr.Personnel.model.dao.zhouxiong.CwaRemDao;

@Service
@Transactional(rollbackFor=Exception.class)
public class CwaRemService {
	
	@Autowired
	private CwaRemDao cyd;
	
	
	String[] array1= {"01","02","03","04","05","06","07","08","09","10","11","12"};
	String[] array2= {"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"};
	
	public PerCwaRem findOne(String itime) {
		try {
//			System.err.println(cyd.findOne(itime).getItime()+"==="+cyd.findOne(itime).getIremind());
			return cyd.findOne(itime);
		} catch (Exception e) {
			return null;
		}
	}
	
	public List<PerCwaRem> findAll(String imouthyear) {
		try {
			return cyd.findAll(imouthyear);
		} catch (Exception e) {
			return null;
		}
	}
	
	public String afaf(Timestamp timestamp) {
		try {
			int year=timestamp.getYear()+1900;
			int mouth=timestamp.getMonth()+1;
			int day=timestamp.getDate();
			
			String imouthyear=null;
			for(int z=0;z<12;z++) {
				if(mouth==Integer.valueOf(array1[z])) {
					imouthyear=array2[z]+" "+year;
				}
			}
			return imouthyear;
		} catch (Exception e) {
			return null;
		}
	}
	
	public String ggese(Timestamp timestamp) {
		try {
			String itime=null;
			int year=timestamp.getYear()+1900;
			int mouth=timestamp.getMonth()+1;
			int day=timestamp.getDate();
	
			itime=year+","+mouth+","+day;
			return itime;
		} catch (Exception e) {
			return null;
		}
	}
	
	public List<PerCwaRem> findMany(Timestamp timestamp) {
		try {
			String itime = ggese( timestamp);
			List<PerCwaRem> findMany = cyd.findMany(itime);
//			System.err.println("长度："+findMany.size());
			findMany.forEach(d->System.err.println(d));
			return findMany;
		} catch (Exception e) {
			return null;
		}
	}
	
	public List<PerCwaRem> findMany(String timestamp) {
		try {
			return cyd.findMany(timestamp);
		} catch (Exception e) {
			return null;
		}
	}
	
	//新增提醒
	public void addCalender(String Iremind,Timestamp imouthyear) {
		try {
			String imouthyears = afaf( imouthyear);
			String itime = ggese( imouthyear);
			
			PerCwaRem cy=new PerCwaRem();
			cy.setIremind(Iremind);
			cy.setImouthyear(imouthyears);
			cy.setItime(itime);
			cyd.save(cy);
		} catch (Exception e) {
			// TODO: handle exception
		}
	}

}